package com.example.my.shop.mybatis.controller;

import com.example.my.shop.mybatis.TbUser;
import com.example.my.shop.mybatis.service.Imp.TbUserServiceImpl;
import com.example.my.shop.mybatis.service.TbUserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/addUser")
public class AddUserController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TbUserService tbUserService = new TbUserServiceImpl();
        String username = req.getParameter("username");
        String email = req.getParameter("email");
        String password = req.getParameter("password");
        String phone = req.getParameter("phone");

        TbUser user = new TbUser(username, email, password, phone);
        boolean b = tbUserService.addUser(user);

        req.setAttribute("message", b ? "registered" : "not registered");

        req.getRequestDispatcher("/getUsers").forward(req, resp);
    }
}
